var app = getApp();
const http = app.http;
const util = app.util;
// pages/zhongbao_pay/geshui.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    loading: false,
    tip: '上拉加载',
    is_pull: true,
    page: 1,
    statistics: [],
    year: '',
    month: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var time = util.formatTime(new Date());
    var t = time.substr(0, 7);
    var year = time.substr(0, 4)
    var month = time.substr(5, 2)
    this.setData({
      year: year,
      month: month
    })
    let all = year + '-' + month;
    this.loadlist(1, all)
  },
  loadlist: function (page, month) {
    var that = this;
    this.setData({
      loading: true,
      tip: '正在加载',
    });
    http.$ajax({
      url: 'v2.taskmoney/getTaxList',
      data: {
        page: page,
        month: month,
      }
    }, {
        success: (res) => {
          var data = res.data;
          var hasmore = true;
          var page = that.data.page;
          if(page==1){
            var statistics = data.statistics;
            that.setData({ statistics: statistics})
          }   
          var data = data.list.data  ;  
          if (data.length < 15) {
            hasmore = false;
          }
         

          that.setData({
            hasmore: hasmore,
            list: data,
            page: page,
            date: month
          })
        },
        complete(res) {
          console.log(res);
          let tip = '';
          if (app.util.isString(res)) {
            app.info(res);
            tip = '上拉加载';
          } else if (!app.util.isUndefined(res.data.list.data) && app.util.isArray(res.data.list.data)) {
            if (res.data.list.data.length < 15) {
              that.data.is_pull = false;
              tip = '没有更多数据'
            } else {
              tip = '上拉加载';
            }
          }
          that.setData({
            loading: false,
            tip: tip,
          })
        }
      })
  },
  bindTimeChange: function (e) {
    var date = e.detail.value
    var year = date.substr(0, 4);
    var month = date.substr(5, 2);
    this.setData({
      year: year,
      month: month,
      list: [],
      loading: false,
      tip: '上拉加载',
      is_pull: true,
      statistics:[],
      page:1
    })
    this.loadlist(1,  date)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (that.data.hasmore) {
      var page = that.data.page;
      page += 1;
      that.setData({page:page})
      that.loadlist(page,  that.data.date);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})